package com.spyx.product.controller;


import com.atyx.spyx.model.product.AttrGroup;
import com.atyx.spyx.vo.product.AttrGroupQueryVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.spyx.product.service.AttrGroupService;
import com.spyx.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 属性分组 前端控制器
 * </p>
 *
 * @author yhp
 * @since 2024-05-15
 */
@RestController
@RequestMapping("/admin/product/attrGroup")
//@CrossOrigin
@Api(tags = "平台属性分组管理")
public class AttrGroupController {
    @Autowired
    private AttrGroupService attrGroupService;

    @ApiOperation("分页+模糊查")
    @GetMapping("{page}/{limit}")
    public Result  getattrGroupList(
            @PathVariable("page")Integer page,
            @PathVariable("limit") Integer limit,
            AttrGroupQueryVo queryVo
            ){
        //调取service层
        //   public  IPage<当前表的实体类>  自定义方法名(Page page, XXXQueryVo vo)
        Page p1 = new Page(page, limit);
        IPage<AttrGroup> groupList = attrGroupService.getGroupList(p1, queryVo);
        return Result.ok(groupList);
    }

    @ApiOperation("根据主键查询")
    @GetMapping("get/{id}")
    public Result getById(@PathVariable("id") Long id){
        AttrGroup byId = attrGroupService.getById(id);
        return Result.ok(byId);
    }
    @ApiOperation("添加")
    @PostMapping("save")
    public Result add(@RequestBody AttrGroup attrGroup){
        attrGroupService.save(attrGroup);
        return Result.ok();
    }

    @ApiOperation("修改")
    @PutMapping("update")
    public Result update(@RequestBody AttrGroup attrGroup){
        attrGroupService.updateById(attrGroup);
        return Result.ok();
    }
    @ApiOperation("删除")
    @DeleteMapping("remove/{id}")
    public Result deleteById(@PathVariable Integer id){
        attrGroupService.removeById(id);
        return Result.ok();
    }

    @ApiOperation("批量删除")
    @DeleteMapping("batchRemove")
    public Result batchRemove(@RequestBody List<Long> idList){
        attrGroupService.removeByIds(idList);
        return Result.ok();
    }

    @ApiOperation("查询全部")
    @GetMapping("findAllList")
    public Result findAllList(){
        List<AttrGroup> list = attrGroupService.findAllList();
        return Result.ok(list);
    }

}

